package com.nisco.dms.entity;

import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.google.common.collect.Lists;

@Entity
@Table(name = "Du_User")
// 默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "com.nisco.dms.entity")
public class User extends CoreEntity {

	@Column
	private String strSn;
	
	@Column
	private String strAccount;

	@Column
	private String strName;
	
	@Column
	private String strNickName;
	
	@Column
	private String strPassword;

	@Transient
	private String plainPassword;

	@Column
	private String strSalt;

	@Column
	private String strPhone;

	@Column
	private String strEmail;

	/**
	 * 帐号创建时间
	 */
//	@Temporal(TemporalType.TIMESTAMP)
//	@Column(updatable = false)
//	private Date createTime;

	/**
	 * 使用状态disabled，enabled
	 */
	@Column(nullable = false, length = 16)
	private String strStatus = "enabled";

	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
	@OrderBy("intPriority ASC")
	private List<UserRole> userRoles = Lists.newArrayList();

	@ManyToOne
	@JoinColumn(name = "deptId")
	@NotFound(action=NotFoundAction.IGNORE)
	private Department dept;


	public String getStrSn()
	{
		return strSn;
	}

	public void setStrSn(String strSn)
	{
		this.strSn = strSn;
	}

	public String getStrAccount()
	{
		return strAccount;
	}

	public void setStrAccount(String strAccount)
	{
		this.strAccount = strAccount;
	}

	public String getStrName()
	{
		return strName;
	}

	public void setStrName(String strName)
	{
		this.strName = strName;
	}

	public String getStrNickName()
	{
		return strNickName;
	}

	public void setStrNickName(String strNickName)
	{
		this.strNickName = strNickName;
	}

	public String getStrPassword()
	{
		return strPassword;
	}

	public void setStrPassword(String strPassword)
	{
		this.strPassword = strPassword;
	}

	public String getPlainPassword()
	{
		return plainPassword;
	}

	public void setPlainPassword(String plainPassword)
	{
		this.plainPassword = plainPassword;
	}

	public String getStrSalt()
	{
		return strSalt;
	}

	public void setStrSalt(String strSalt)
	{
		this.strSalt = strSalt;
	}

	public String getStrPhone()
	{
		return strPhone;
	}

	public void setStrPhone(String strPhone)
	{
		this.strPhone = strPhone;
	}

	public String getStrEmail()
	{
		return strEmail;
	}

	public void setStrEmail(String strEmail)
	{
		this.strEmail = strEmail;
	}

	

	public String getStrStatus()
	{
		return strStatus;
	}

	public void setStrStatus(String strStatus)
	{
		this.strStatus = strStatus;
	}

	public List<UserRole> getUserRoles()
	{
		return userRoles;
	}

	public void setUserRoles(List<UserRole> userRoles)
	{
		this.userRoles = userRoles;
	}


	
	public Department getDept()
	{
		return dept;
	}

	public void setDept(Department dept)
	{
		this.dept = dept;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

}
